package com.xxx.nio;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Iterator;
import java.util.Map;
import java.util.stream.Stream;

/**
 * @version v1.0
 * @Description
 * @Author admin
 * @date 2021/7/23  14:52
 * @Copyright
 */
public class pathDome {
    public static void main(String[] args) throws IOException {
        //m1();

       // m2();
        //m3();
       // m4();
//        m5();
        Path path = Paths.get("C:\\Users\\admin\\Desktop\\Git\\a");
        Files.walkFileTree(path, new FileVisitor<Path>() {
            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                return null;
            }

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                return null;
            }

            @Override
            public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
                return null;
            }

            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                return null;
            }
        });








    }

    private static void m5() throws IOException {
        Path path = Paths.get("C:\\Users\\admin\\Desktop\\Git\\a");
        Stream<Path> list = Files.list(path);
        Iterator<Path> iterator = list.iterator();
        while (iterator.hasNext()){
             Path next = iterator.next();
            System.out.println("next = " + next);
        }
    }

    private static void m4() throws IOException {
        Path path = Paths.get("C:\\Users\\admin\\Desktop\\Git\\a\\io.txt");
        Path paths = Paths.get("C:\\Users\\admin\\Desktop\\Git\\a\\ios.txt");

        // Files.copy(path,paths, StandardCopyOption.REPLACE_EXISTING);
        Files.delete(paths);
    }

    private static void m3() throws IOException {
        Path path = Paths.get("C:\\Users\\admin\\Desktop\\Git\\a\\io.txt");
        BufferedWriter bufferedWriter = Files.newBufferedWriter(path);
        bufferedWriter.write("asd");
        bufferedWriter.close();


        BufferedReader bufferedReader = Files.newBufferedReader(path);
        System.out.println(bufferedReader.readLine());
        bufferedReader.close();
    }

    private static void m2() throws IOException {
        //        Path path = Paths.get("C:\\Users\\admin\\Desktop\\Git\\a\\io.jpg");
//         Files.createFile(path);

        Path dir = Paths.get("C:\\Users\\admin\\Desktop\\Git\\a\\io");
//        Files.createDirectories(dir);

        Path path = Paths.get("C:\\Users\\admin\\Desktop\\Git\\a\\io.jpg");

        Map<String, Object> stringObjectMap = Files.readAttributes(path, "*");
//        System.out.println(stringObjectMap);
//        {
//                lastAccessTime = 2021 - 07 - 23 T07:21:48.290841 Z,
//                lastModifiedTime = 2021 - 07 - 23 T07:19:46.225511 Z,
//                size = 0,
//                creationTime = 2021 - 07 - 23 T07:19:46.225511 Z,
//                isSymbolicLink = false,
//                isRegularFile = true,
//                fileKey = null,
//                isOther = false,
//                isDirectory = false
//        }
        System.out.println(Files.getLastModifiedTime(path));//最后修改的时间
        System.out.println(Files.isDirectory(path));//是否是目录
        System.out.println(Files.isRegularFile(path));//是否是隐藏
        System.out.println(Files.isReadable(path));//是否是只读
        System.out.println(Files.size(path));//文件大小
    }

    private static void m1() {
        Path path = Paths.get("C:\\Users\\admin\\Desktop\\Git\\a\\io.jpg");

        //path-->>file
        path.toFile();

        File file = new File("C:\\Users\\admin\\Desktop\\Git\\a\\io.apg");
        //file-->>path
        file.toPath();
    }
}
